package com.itheima.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.mapper.CmsSubjectProductRelationMapper;
import com.itheima.pojo.db.CmsSubjectProductRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
/**
 * @author chensen
 * @create 2022/10/14/20:29
 */
@DubboService
public class CmsSubjectProductRelationApiImpl implements CmsSubjectProductRelationApi {
    @Autowired
    private CmsSubjectProductRelationMapper cmsSubjectProductRelationMapper;


    @Override
    public void insertList(List<CmsSubjectProductRelation> list, Long productId) {
        for (CmsSubjectProductRelation cmsSubjectProductRelation : list) {
            cmsSubjectProductRelation.setId(null);
            cmsSubjectProductRelation.setProductId(productId);
            cmsSubjectProductRelationMapper.insert(cmsSubjectProductRelation);
        }
    }

    @Override
    public void deleteById(Long id) {
        cmsSubjectProductRelationMapper.delete(new LambdaQueryWrapper<CmsSubjectProductRelation>().eq(CmsSubjectProductRelation::getProductId, id));
    }

    @Override
    public List<CmsSubjectProductRelation> selectById(Long id) {
        return cmsSubjectProductRelationMapper.selectList(new LambdaQueryWrapper<CmsSubjectProductRelation>().eq(CmsSubjectProductRelation::getProductId, id));
    }
}
